home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Games of Daze
/
Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso
/
x2ftp
/
msdos
/
indeo
/
nwxmas
/
xd_init.c
< prev
next >
Wrap
Text File
|
1993-12-13
|
6KB
|
254 lines
/*
** ╔══════════════════════════════════════════════════════════════╗
** ║ ║
** ║ Copyright (c) 1993 Digital Video Arts, Ltd. ║
** ║ All Rights Reserved ║
** ║ ║
** ╚══════════════════════════════════════════════════════════════╝
**
** Christmas card demo
**
** file: xd_init.c - handle all initialization
*/
#include <stdio.h>
#include <fcntl.h>
#include "nw.h"
#include "nwau.h"
#include "nwerrno.h"
#include "xmasdemo.h"
static U16 mempool[] = {0, 0xff00, 0xffff, 0xffff};
void InitNewworld()
{
ColorVal c;
Rect r;
Point p;
Font *f;
DisplayStat far *ds;
NwBegin();
ds = VidStat();
if(ds->ver_major < 3)
NwErr("This demo requires NewWorld version 3.0 or later");
VidMemInit(mempool);
//
// preload microcode
//
GrCopyTrans(NULL, &p, NULL, &r, c);
GrCopyMap(NULL, &r, NULL, &p, NULL, &r, 1);
GrFontWidth(NULL,XMASGREETING,1);
GrFontOpen(NULL);
GrFontHeight(NULL);
GrFontClose(NULL);
GrText(NULL, f, &p, XMASGREETING, 0, 1, c, c, c, c);
GrSpawnBitmap(NULL, &r);
GrScaleFast(NULL, &r, NULL, &r);
GrRect(NULL, &r, c, 1, 1, RopDst);
GrReplace(NULL, &r.origin, NULL, &r, 0xf0, 0xff,0xfe, NULL, 1, 1);
GrColor(NULL, P_C, c);
GrEllipse(NULL, &r, c, 1);
}
void InitDisplays()
{
VidRegGen(d[0] = VidDispAlloc(VideoC, 256, 240, BM1Y, BM1VU));
VidRegGen(d[1] = VidDispAlloc(VideoC, 256, 240, BM2Y, BM2VU));
VidRegGen(d[2] = VidDispAlloc(VideoC, 256, 240, BM3Y, BM3VU));
VidRegGen(d[3] = VidDispAlloc(VideoC, 256, 240, BM4Y, BM4VU));
VidRegGen(d[4] = VidDispAlloc(VideoC, 256, 240, BM5Y, BM5VU));
VidDisplays(&d[0], 5);
VidRegGen(onscreen = VidDispAlloc(VideoC,512,476,ONSCRY,ONSCRVU));
//
// Note: these offscreen bitmaps don't need any V and U bitmaps since
// all offscreen operations will only be performed on the Y or CLUT
// bitmap.
//
VidRegGen(map = VidDispAlloc(VideoC, 256, 240, MAPY, 0l));
VidRegGen(mapg = VidDispAlloc(Graphic16, 128, 240, MAPY, 0l));
VidRegGen(balls = VidDispAlloc(VideoC, 256, 240, BALLSY, 0L));
VidRegGen(warp = VidDispAlloc(VideoC, 256, 240, WARPY, 0L));
VidRegGen(text = VidDispAlloc(VideoC, 256, 240, TEXTY, TEXTVU));
}
void InitAvss()
{
AvS *s;
vobj vsh;
int foundvideo = 0;
vsh.size = 0x10000L;
vsh.bound = 0;
vsh.addr = GrWork;
a = AvOpen(VIDEOFILE, O_RDONLY, &vsh);
if(!a) NwErr("Can't open "VIDEOFILE);
//
// Disable all but the first video stream.
//
for(s= a->s; s ; s = s->next) {
switch(s->hdr.subtype) {
case AVS_Pad:
case AVS_UnderLay:
case AVS_Audio:
s->enable = 0;
break;
default:
if(foundvideo) {
s->enable = 0;
break;
}
//
// Now, force the input area to be hard coded.
//
s->cbe[AvSCb_Data].cb->data.addr = YVU_BUFFER;
s->cbe[AvSCb_Data].cb->data.size = YVU_SIZE;
foundvideo = 1;
break;
}
}
//
// Start a read
//
AvRead(a, a->framecnt);
//
// Preload input buffers
//
AvPreload(a, a->framecnt);
//
// Disable the full screen video since we are going to copy to
// the screen.
VidSpeed(VID_IGNORE_MOTIONVIDEO);
}
static void load(Bitmap *b, char *file)
{
ImH *img;
Point p;
if(img = GrImOpen(file, O_RDONLY)) {
POINT(p,0,0);
GrImLoad(b, &p, img, 1);
McWait(); /* in case decompressing not done */
GrImClose(img);
}
else
NwErr("can't open image file\n");
}
void InitImages()
{
int i;
int height, length;
Rect r;
Point p;
Font *f;
ColorVal black, white, c, red, ltred, dkred;
RGB(white, 255,255,255);
RGB(red, 255, 0, 0);
RGB(ltred,255,128,128);
RGB(dkred,128,0,0);
RGB(black, 0, 0, 0);
//
// Clear out old VU bitmaps to avoid smearing
//
RECT(r, 0, 0, 512, 484);
RGB(c, 0, 0, 0);
onscreen->dbm.GrPlanes = P_V|P_V;
GrRect(&onscreen->dbm, &r, c, 1, 1, RopDst);
//
// Load the image files
//
onscreen->dbm.GrPlanes = P_YVU;
load(&onscreen->dbm,STILLFILE);
load(&mapg->dbm,MAPFILE);
//
// Add greeting
//
f = GrFontOpen(XMASFONT);
if(!f) NwErr("Can't open "XMASFONT);
height = GrFontHeight(f);
length = GrFontWidth(f,XMASGREETING,1);
POINT(p, 256-length/2, 480 - height*2);
onscreen->dbm.GrPlanes = P_C;
GrText(&onscreen->dbm, f, &p, XMASGREETING, 0, 1, white, black,
black, black); // red on top
p.x--; p.y--;
GrText(&onscreen->dbm, f, &p, XMASGREETING, 0, 1, black, red,
ltred, dkred); // shadow behind
GrFontClose(f);
//
// Prepare off screen logo bitmap and load logo
//
text->dbm.GrPlanes = P_C;
CLT(c, 0xfe);
RECT(r, 0,0,256,240);
GrRect(&text->dbm, &r, c, 1, 1, RopDst);
load(&text->dbm,LOGOFILE);
RECT(r, 0, 0, 128, 240);
//
// turn off the lower order bit of each pixel in the y plane so
// that it will be interpreted as a CLUT pixel
//
text->dbm.GrPlanes = P_C;
//
// Replace all pixel in the range of 0xf0 - 0xff with the transparency
// color( 0xfe) and all other pixels to white
//
GrReplace(&text->dbm, &r.origin, &text->dbm, &r, 0xf0, 0xff,
0xfe, GrColor(&text->dbm, P_C, white), 1, 1);
//
// Spawn copies of the balls on the screen and color them in
// on the chroma planes only
//
onscreen->dbm.GrPlanes = P_V | P_U;
for(i=0; i< MAXBALLS; i++) {
RECT(r, Balls[i].p.x, Balls[i].p.y,
warps[Balls[i].warpno].corner.x,
warps[Balls[i].warpno].corner.y);
Balls[i].spawn = GrSpawnBitmap(&onscreen->dbm, &r);
RGB(c, Balls[i].red, Balls[i].green, Balls[i].blue);
r.corner.x = (r.corner.x*4)/5;
r.origin.x += 4;
r.origin.y += 4;
r.corner.x -=4;
r.corner.y -= 4;
GrEllipse(&onscreen->dbm, &r, c, 1);
}
//
// Clear the balls bitmap to the transparency color
//
YVU(c, 0, 0, 0);
RECT(r, 0, 0, 256, 240);
GrRect(&balls->dbm, &r, c, 1, 1, RopDst);
}
void InitAudio()
{
int fd;
fd = VidOpen(AUDIOFILE, O_RDONLY|O_BINARY);
if(fd <= 0) NwErr("Can't open "AUDIOFILE);
audiolength = VidFileLength(fd);
VidRead(fd,AUDIOBUFFER,audiolength);
channel = AudChOpen("adpcm4e", 2, // play
11760, // filter
4, // subframes
(unsigned int)(132300L/4L), // sample rate
30, // frames/second
100, // left volume
100, // right volume
0);
}